﻿Imports DTO

Public Class KhachHangDAO
    Public Sub Them(ByVal khDTO As KhachHangDTO)
        Try
            Dim db As New QuanLyNhaSachDataContext
            Dim kh As New KhachHang
            kh.CMND = khDTO.CMND
            kh.TenKH = khDTO.TenKH
            kh.DiaChi = khDTO.DiaChi
            kh.Phone = khDTO.Phone
            kh.Email = khDTO.Email
            kh.SoTienNo = khDTO.SoTienNo

            db.KhachHangs.InsertOnSubmit(kh)
            db.SubmitChanges()
        Catch ex As Exception
        End Try
    End Sub

    Public Function TimTheoCMND(ByVal cmnd As String) As KhachHang
        Dim kh As New KhachHang
        Try
            Dim db As New QuanLyNhaSachDataContext
            kh = db.KhachHangs.Single(Function(p) p.CMND = cmnd)
            Return kh
        Catch ex As Exception

        End Try
        Return Nothing
    End Function

    Public Sub CapNhatTienNo(ByVal khDTO As KhachHangDTO)
        Dim db As New QuanLyNhaSachDataContext
        Dim kh = db.KhachHangs.Single(Function(p) p.CMND = khDTO.CMND)

        kh.SoTienNo = kh.SoTienNo + khDTO.SoTienNo

        db.SubmitChanges()
    End Sub
End Class
